package cn.itcast.itcaststore.web.servlet.manager;

import cn.itcast.itcaststore.domain.Orders;
import cn.itcast.itcaststore.serive.OrderService;
import cn.itcast.itcaststore.serive.impl.OrderServiceImpl;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;
import java.util.List;

/**
 * 查询所有订单
 */
@WebServlet("/admin/findOrders")
public class FindOrdersServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doPost(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {


        OrderService orderService = new OrderServiceImpl();
        try {
            List<Orders> ordersList = orderService.findAllOrder();
            req.setAttribute("orders", ordersList);
            req.getRequestDispatcher("/admin/orders/list.jsp").forward(req, resp);
        } catch (SQLException e) {
            e.printStackTrace();
        }

    }
}
